import wxLogin from './wxtools/wxlogintools.js'
import alipayLogin from './alipaytools/alipaylogintools.js'

function login() {
	// #ifdef MP-WEIXIN
	console.log('MP-WEIXIN环境...');
	return new Promise((resolve, reject) => {
		wxLogin.login().then(res => {
			console.log('完毕');
			resolve('wx login complete!')
		})
	})
	// #endif
	// #ifdef MP-ALIPAY
	console.log('MP-ALIPAY环境....');
	return new Promise((resolve, reject) => {
		alipayLogin.login().then(res => {
			console.log('完毕');
			resolve('alipay login complete!')
		})
	})
	// #endif
}

function isLogin() {
	const app = getApp()
	let openid = uni.getStorageSync(app.globalData.session.userKey);
	if (openid) {
		return true
	} else {
		return false
	}
}

function logout() {
	const app = getApp()
	uni.removeStorageSync(app.globalData.session.userKey);
	uni.removeStorageSync(app.globalData.session.userType);
	uni.removeStorageSync(app.globalData.session.userIngo);
	uni.removeStorageSync(app.globalData.session.businessInfo);
	uni.removeStorageSync(app.globalData.session.userAccountType);
}

module.exports = {
	login,
	isLogin,
	logout
}